using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
using System.Windows.Forms;
using System.Data;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace DMV {
	public class Server : System.Windows.Forms.Form {
		protected TcpChannel chan1 = new TcpChannel(Dimok.Config.DMV.Port);
		private System.ComponentModel.Container components = null;

		public Server() {
			InitializeComponent();
			try {
				ChannelServices.RegisterChannel(chan1);
				RemotingConfiguration.Configure(AppDomain.CurrentDomain.FriendlyName+".config");
				RemotingConfiguration.RegisterWellKnownServiceType(
					typeof(DMV.Remote),
					Dimok.Config.DMV.URL,
					WellKnownObjectMode.Singleton);
			}
			catch(Exception exc) {
				MessageBox.Show(exc.Message+Environment.NewLine+exc.StackTrace);
			}
		}
		protected override void Dispose( bool disposing ) {
			if( disposing ) {
				if (components != null) {
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		private void InitializeComponent() {
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Server));
			// 
			// Server
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(194, 0);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "Server";
			this.Text = "DMV Server";
			this.Load += new System.EventHandler(this.Server_Load);

		}
		#endregion

		[STAThread]
		static void Main() {
			Application.Run(new Server());
		}

		private void Server_Load(object sender, System.EventArgs e) {
			Text += "("+Dimok.Config.DMV.URL+":"+Dimok.Config.DMV.Port+") : "+System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
		}
	}
}